package com.cms.content.jobs.service.impl;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cms.framework.utils.BeanUtilEx;
import com.cms.framework.utils.page.PageView;
import com.cms.content.jobs.dao.JobsDAO;
import com.cms.content.jobs.pojo.Jobs;
import com.cms.content.jobs.pojo.dto.JobsDTO;
import com.cms.content.jobs.service.JobsService;
@Service
public class JobsServiceImpl implements JobsService {
	@Autowired
	JobsDAO jobsDAO;
	@Override
	public boolean saveJobs(Jobs jobs) {
		if(jobs.getId()==null){
			return jobsDAO.insert(jobs)>0;
		}else{
			return jobsDAO.updateByPrimaryKey(jobs)>0;
		}
	}

	@Override
	public boolean deleteById(Integer id) {
		return jobsDAO.deleteByPrimaryKey(id)>0;
	}

	@Override
	public Jobs findById(Integer id) {
		return jobsDAO.selectByPrimaryKey(id);
	}

	@Override
	public List<Jobs> findList() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public PageView<JobsDTO> findListByPage(PageView<JobsDTO> pageView,
			JobsDTO jobsDTOParams) {
		List<Jobs> list=jobsDAO.selectByPage(pageView, jobsDTOParams);
		List<JobsDTO> dtoList=new ArrayList<JobsDTO>();
		for(Jobs jobs:list){
			JobsDTO jobsDTO=new JobsDTO();
			try {
				BeanUtilEx.copyProperties(jobsDTO, jobs);
				//friendlinkDTO.setPcUrl("pcUrl");
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				e.printStackTrace();
			}
			dtoList.add(jobsDTO);
		}
		pageView.setRecords(dtoList);
		return pageView;
	}

}
